home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / __MANDEL / MANDELBR / CMANDELC.C < prev    next >
Text File  |  1992-03-28  |  2KB  |  97 lines

  1. //    CMandelCheckPhase.c
  2.  
  3. #include "CMandelCheckPhase.h"
  4. #include "CMandelDividePhase.h"
  5.  
  6. void
  7. CMandelCheckPhase::IMandelCheckPhase(CMandelDoc *theDoc, CMandelPhase *theNextPhase,
  8.     Rect theRect)
  9. {
  10.     CMandelPhase::IMandelPhase(theDoc, theNextPhase);
  11.     
  12.     itsRect = theRect;
  13. }
  14.  
  15. CMandelPhase *
  16. CMandelCheckPhase::Perform(void)
  17. {
  18.     TDwell        aDwell;
  19.  
  20.     if (CheckRect(&aDwell))
  21.         FillRect(aDwell);
  22.     else
  23.     {
  24.         CMandelDividePhase *    aDividePhase;
  25.         
  26.         aDividePhase = new CMandelDividePhase;
  27.         aDividePhase->IMandelDividePhase(itsDoc, itsNextPhase, itsRect);
  28.         itsNextPhase = aDividePhase;
  29.     }
  30.     
  31.     return itsNextPhase;
  32. }
  33.  
  34. Boolean
  35. CMandelCheckPhase::CheckRect(TDwell *theDwell)
  36. {
  37.     TDwell    aDwell, *aDwellP, *aDwellQ, *aDwellPtr = *itsDoc->itsDwellsH;
  38.     short    aMapWidth = itsDoc->itsWidth;
  39.     
  40.     aDwellP = aDwellQ = aDwellPtr + (long)itsRect.top * aMapWidth;
  41.     aDwellP += itsRect.left;
  42.     aDwellQ += itsRect.right;
  43.     aDwell = *aDwellP++;
  44.     while (aDwellP <= aDwellQ)
  45.         if (*aDwellP++ != aDwell)
  46.             return FALSE;
  47.     
  48.     aDwellP = aDwellQ = aDwellPtr + (long)itsRect.bottom * aMapWidth;
  49.     aDwellP += itsRect.left;
  50.     aDwellQ += itsRect.right;
  51.     while (aDwellP <= aDwellQ)
  52.         if (*aDwellP++ != aDwell)
  53.             return FALSE;
  54.     
  55.     aDwellP = aDwellPtr + (long)itsRect.top * aMapWidth + itsRect.left;
  56.     aDwellQ = aDwellPtr + (long)itsRect.bottom * aMapWidth + itsRect.left;
  57.     for (aDwellP += aMapWidth; aDwellP < aDwellQ; aDwellP += aMapWidth)
  58.         if (*aDwellP != aDwell)
  59.             return FALSE;
  60.     
  61.     aDwellP = aDwellPtr + (long)itsRect.top * aMapWidth + itsRect.right;
  62.     aDwellQ = aDwellPtr + (long)itsRect.bottom * aMapWidth + itsRect.right;
  63.     for (aDwellP += aMapWidth; aDwellP < aDwellQ; aDwellP += aMapWidth)
  64.         if (*aDwellP != aDwell)
  65.             return FALSE;
  66.     
  67.     *theDwell = aDwell;
  68.     return TRUE;
  69. }
  70.  
  71. void
  72. CMandelCheckPhase::FillRect(TDwell theDwell)
  73. {
  74.     TDwell *    aDwellP, *aDwellQ, *aP, *aQ, *aDwellPtr = *itsDoc->itsDwellsH;
  75.     unsigned    aMapWidth, h, v;
  76.     
  77.     aMapWidth = itsDoc->itsWidth;
  78.     
  79.     aDwellP = aDwellQ = aDwellPtr + itsRect.left + 1;
  80.     aDwellP += (long)(itsRect.top + 1) * aMapWidth;
  81.     aDwellQ += (long)(itsRect.bottom - 1) * aMapWidth;
  82.     
  83.     aQ = aDwellPtr + itsRect.right - 1;
  84.     aQ += (long)(itsRect.top + 1) * aMapWidth;
  85.     
  86.     while (aDwellP <= aDwellQ)
  87.     {
  88.         aP = aDwellP;
  89.         while (aP <= aQ)
  90.             *aP++ = theDwell;
  91.             
  92.         aDwellP += aMapWidth;
  93.         aQ += aMapWidth;
  94.     }
  95. }
  96.  
  97.